package aeso.br.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import aeso.br.model.Cliente;


import aeso.br.util.HibernateUtil;

public class ClienteDAO {
	public void add (Cliente cliente){
		 Session session = HibernateUtil.getSession().openSession();
	        Transaction t = session.beginTransaction();
	        session.save(cliente);
	        t.commit();
		
	}

	public Cliente getCliente (int id){
		
		Session session = HibernateUtil.getSession().openSession();
		return (Cliente) session.load(Cliente.class, id);
		
		
	}
	
	public List<Cliente> listarCliente(){
		Session session = HibernateUtil.getSession().openSession();
		Transaction t = session.beginTransaction();
		List lista  = session.createQuery("from cliente").list();
		t.commit();
		return lista;
		
	}
	
	public void remover(Cliente cliente){
		Session session = HibernateUtil.getSession().openSession();
		Transaction t = session.beginTransaction();
		session.delete(cliente);
		
	}
	
	public void alterar (Cliente cliente){
		Session session = HibernateUtil.getSession().openSession();
		Transaction t = session.beginTransaction();
		session.update(cliente);
		t.commit();
		
		
	}



}
